package org.vt.scheduleapp;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import android.content.Context;

public class LocReader {
	private final String FILENAME = "loc_file.txt";
	private FileInputStream fis;
	//private final String newLine = "[\n]";
	private final String comma = "[,]";
	private final String colon = "[:]";
	private Context mCtx;
	
	public LocReader(Context context)
	{
		mCtx = context;
	}
	
	public List<Loc> getAllLocs() throws IOException, FileNotFoundException
	{
		fis = mCtx.openFileInput(FILENAME);
		List<Loc> locs = new ArrayList<Loc>();
		BufferedReader br = new BufferedReader(new InputStreamReader(fis));
		String line = br.readLine();
		while((line = br.readLine())!=null)
		{
			String[] t1 = line.split(comma);
			String[] n = t1[0].split(colon);
			String name = n[1];
			String[] a = t1[1].split(colon);
			double lat = Double.parseDouble(a[1].trim());
			String[] o = t1[2].split(colon);
			double lon = Double.parseDouble(o[1].trim());
			locs.add(new Loc(name, lat, lon));
		}
		fis.close();
		return locs;
	}
}
